package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;



import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
/**
 * A simple {@link Fragment} subclass.
 * Use the {@link Fragment2#newInstance} factory method to
 * create an instance of this fragment.
 */
public class Fragment2 extends Fragment {


    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    //这里是mainactivity的内容

    List<Person> personList=new ArrayList<>();
    private RecyclerView recyclerView;
    // 定义 ActivityResultLauncher
    private ActivityResultLauncher<Intent> activityResultLauncher;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


// 初始化 ActivityResultLauncher

     View  view1=inflater.inflate(R.layout.activity_main4, container, false);


        recyclerView=view1.findViewById(R.id.recycle);

//        recyclerView.setAdapter();

        Person person1=new Person("whl","19307132956",R.drawable.baseline_boy_24);
        Person person2=new Person("zkq","21231231312",R.drawable.abc);
        personList.add(person1);
        personList.add(person2);
        LinearLayoutManager layoutManager =new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);

        Adapter adapter =new Adapter(getContext(), personList);
        recyclerView.setAdapter(adapter);

      //1-1
//1-1
        // Inflate the layout for this fragment
       // return inflater.inflate(R.layout.activity_main4, container, false);
        return view1;
    }
}